<template>
  <el-container>
    <el-aside style="background: #fff; width: fit-content; min-width: 200px">
      <common-aside :menus="myMenus"></common-aside>
    </el-aside>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>
<script>
const menus = {
  student: [
    {
      name: "课程",
      path: "/my/stu-course",
      icon: "menu",
    },
    {
      name: "考试",
      path: "/my/exam",
      icon: "menu",
    },
    {
      name: "评价",
      path: "/my/evaluate",
      icon: "s-check",
    },
    {
      name: "成绩统计",
      path: "score",
      icon: "s-order",
      children: [
        {
          name: "理论成绩",
          path: "/my/score-statistic",
        },
        {
          name: "仿真成绩",
          path: "/my/simulation-performance",
        },
      ],
    },
    {
      name: "绩效评估",
      path: "performance",
      icon: "s-order",
      children: [
        {
          name: "个人评估",
          path: "/my/individual-performance-evaluation",
        },
        {
          name: "班级水平评估",
          path: "/my/class-performance-evaluation",
        },
      ],
    },
  ],
  teacher: [
    {
      name: "课程",
      path: "/my/teach-course",
      icon: "tickets",
    },
    {
      name: "批阅",
      path: "/my/inspection",
      icon: "s-check",
    },
    {
      name: "考试",
      path: "/my/teach-exam",
      icon: "s-flag",
    },
    {
      name: "题库",
      path: "/my/test-base-manage",
      icon: "folder-opened",
    },
    {
      name: "图1",
      path: "/my/topo",
      icon: "folder-opened",
    },
    {
      name: "图2",
      path: "/my/graphs",
      icon: "folder-opened",
    },
    {
      name: "数据统计",
      path: "/my/data-statistic",
      icon: "folder-opened",
      children: [
        {
          name: "理论学习",
          path: "/my/theory-study",
        },
        {
          name: "教学反馈",
          path: "/my/teach-feedback",
        },
      ],
    },
  ],
  admin: [
    {
      name: "教员管理",
      path: "/my/teacher-manage",
    },
    {
      name: "学员管理",
      path: "/my/student-manage",
    },
    {
      name: "评价管理",
      path: "/my/evaluate-manage",
    },
    {
      name: "评价体系设置",
      path: "/my/evaluate-system",
    },
  ],
};
import { Message } from "element-ui";
import CommonAside from "@/components/CommonAside.vue";
export default {
  name: "My",
  data() {
    return {
      myMenus: [],
    };
  },
  components: { CommonAside },
  beforeMount() {
    // 通过角色控制菜单项
    const role = JSON.parse(localStorage.getItem("userInfo")).role || "student";
    this.myMenus = menus[role];
  },
  beforeRouteEnter(to, from, next) {
    // 假如未登录
    const flag = localStorage.getItem("userInfo") == null;
    if (flag) {
      // 未登录
      Message.warning({
        message: "您还未登录，即将跳转到登录界面",
      });
      setTimeout(() => {
        next({ path: "/login" });
      }, 1000);
    } else {
      next();
    }
  },
};
</script>